<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"      
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:head>
        <title>Danh mục đầu số</title>
        <script>
            function confirmComplete() {
                var answer = confirm("Bạn có chắc chắn muốn xóa bản ghi này?");
                if (answer == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        </script>        
    </h:head>
    <h:body> 
        <link type="text/css" rel="stylesheet" href="../css/main.css" />        
        <style type="text/css">
            .ui-widget{font-size:95% !important;}
            .ui-layout-unit-content{background-color: #E5E5E5;border-width: 0px}      
            .ui-widget{border-width: 0px;color: red}
        </style>
        <div align="center" id="bodyForm" >            
            <div style="width: 100%;">
                <p:layoutUnit id="top" position="north" size="auto">
                    <ui:insert name="menu">
                        <ui:include src="../../templates/menu.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>

                <p:layoutUnit id="center" position="center" size="400">
                    <h1 class="headerbar">Danh mục đầu số</h1>
                    <p:dialog modal="true" widgetVar="statusDialog" header="Đang tìm kiếm..."   
                              draggable="false" closable="false">  
                        <p:graphicImage value="../../images/ajax-loader.gif" />  
                    </p:dialog>
                    <h:form id="form">                        
                        <h:outputText value="Source number: "/>
                        <p:inputText value="#{cOMMUNICATION_CHANNELController.source_numberS}"/>
                        <p:commandButton value="Tìm" update=":form" action="#{cOMMUNICATION_CHANNELController.search()}" onclick="statusDialog.show();" oncomplete="statusDialog.hide();"/>
                        <p:commandButton value="Thêm" onclick="dlgAdd.show()" update=":formAdd" action="#{cOMMUNICATION_CHANNELController.updateInsert()}"/>
                        <p:growl/>
                        <p:dataTable value="#{cOMMUNICATION_CHANNELController.lazyCCModel}" var="c"
                                     paginator="true" paginatorPosition="bottom" rows="20"
                                     rowsPerPageTemplate="20,25,30" lazy="true">
                            <p:column headerText="Source Number">
                                <h:outputText value="#{c.source_number}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Partner">
                                <h:outputText style="float: right" value="#{c.partner.getNameById()}"/>
                            </p:column>
                            <p:column headerText="Type">
                                <h:outputText value="Gọi vào" rendered="#{c.type eq 'I'}" style="float: right"/>
                                <h:outputText value="Gọi ra" rendered="#{c.type eq 'O'}" style="float: right"/>
                            </p:column>                            
                            <p:column headerText="Edit" style="width: 40px">
                                <div align="center">
                                    <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-pencil" onclick="dlgEdit.show()" update=":formEdit" action="#{cOMMUNICATION_CHANNELController.prepareEdit(c)}"/>
                                </div>
                            </p:column>
                            <p:column headerText="Delete" style="width: 40px">
                                <div align="center">
                                    <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-trash" onclick="dlgRemove.show()" update=":formRemove" action="#{cOMMUNICATION_CHANNELController.prepareRemove(c)}"/>
                                </div>
                            </p:column>
                            <p:column headerText="Set group" style="width: 40px">
                                <div align="center">
                                    <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-person" onclick="dlgSetGroup.show()" update=":formSetGroup" action="#{cOMMUNICATION_CHANNELController.prepareSetGroup(c)}"/>
                                </div>
                            </p:column>
                        </p:dataTable>
                    </h:form>
                    <!--dialog Add-->
                    <p:dialog widgetVar="dlgAdd" resizable="false" header="Thêm đầu số" modal="true">
                        <h:form id="formAdd">
                            <p:growl/>
                            <h:panelGrid columns="2">
                                <h:outputText value="Source number: "/>
                                <p:inputText value="#{cOMMUNICATION_CHANNELController.current.source_number}"/>
                                <h:outputText value="Partner: "/>
                                <p:selectOneMenu value="#{cOMMUNICATION_CHANNELController.current.partner.partner_id}" >
                                    <f:selectItems value="#{cOMMUNICATION_CHANNELController.listPartner}" var="c" itemValue="#{c.partner_id}" itemLabel="#{c.partner_name}"/>
                                </p:selectOneMenu>
                                <h:outputText value="Type: "/>
                                <p:selectOneMenu value="#{cOMMUNICATION_CHANNELController.current.type}" >
                                    <f:selectItem itemValue="I" itemLabel="Gọi vào"/>
                                    <f:selectItem itemValue="O" itemLabel="Gọi ra"/>
                                </p:selectOneMenu>
                            </h:panelGrid>
                            <p:commandButton value="Xác nhận" action="#{cOMMUNICATION_CHANNELController.insert()}" oncomplete="dlgAdd.hide()" update=":form"/>
                        </h:form>                        
                    </p:dialog>
                    <!--dialog Edit-->
                    <p:dialog widgetVar="dlgEdit" resizable="false" header="Sửa đầu số" modal="true">
                        <h:form id="formEdit">
                            <p:growl/>
                            <h:panelGrid columns="2">
                                <h:outputText value="Source number: "/>
                                <p:inputText value="#{cOMMUNICATION_CHANNELController.current.source_number}"/>
                                <h:outputText value="Partner: "/>
                                <p:selectOneMenu value="#{cOMMUNICATION_CHANNELController.current.partner.partner_id}" >
                                    <f:selectItems value="#{cOMMUNICATION_CHANNELController.listPartner}" var="c" itemValue="#{c.partner_id}" itemLabel="#{c.partner_name}"/>
                                </p:selectOneMenu>
                                <h:outputText value="Type: "/>
                                <p:selectOneMenu value="#{cOMMUNICATION_CHANNELController.current.type}" >
                                    <f:selectItem itemValue="I" itemLabel="Gọi vào"/>
                                    <f:selectItem itemValue="O" itemLabel="Gọi ra"/>
                                </p:selectOneMenu>
                            </h:panelGrid>
                            <p:commandButton value="Xác nhận" action="#{cOMMUNICATION_CHANNELController.update()}" oncomplete="dlgEdit.hide()" update=":form"/>
                        </h:form>                        
                    </p:dialog>
                   <!--dialog Remove-->
                    <p:dialog widgetVar="dlgRemove" resizable="false" header="Thông báo" modal="true">
                        <h:form id="formRemove">
                            <h:outputText value="Bạn có chắc chắn xóa bản ghi này ?"/> <p:commandButton action="#{cOMMUNICATION_CHANNELController.remove()}" update=":form" oncomplete="dlgRemove.hide()" value="Đồng ý"/>
                        </h:form>
                    </p:dialog>
                    <!--dialog Set group-->
                    <p:dialog widgetVar="dlgSetGroup" resizable="false" header="Set group" modal="true">
                        <h:form id="formSetGroup">
                            <p:growl/>
                            <h:panelGrid columns="2">
                                <h:outputText value="Soure number: "/><h:outputText value="#{cOMMUNICATION_CHANNELController.current.source_number}"/>                                
                            </h:panelGrid>
                            <p:commandButton value="Thêm Nhóm" rendered="#{cOMMUNICATION_CHANNELController.itemsGroup_Channel.rowCount eq 0}" onclick="dlgAddGroup.show()" update=":formAddGroup" action="#{cOMMUNICATION_CHANNELController.clear()}"/><br/><br/>
                            <p:dataTable value="#{cOMMUNICATION_CHANNELController.itemsGroup_Channel}" var="c">                                
                                <p:column headerText="Group">
                                    <h:outputText value="#{cOMMUNICATION_CHANNELController.groupGetName(c.group_id)}"/>
                                </p:column>                                
                                <p:column headerText="From date">
                                    <h:outputText value="#{c.from_date}"/>
                                </p:column>
                                <p:column headerText="To date">
                                    <h:outputText value="#{c.to_date}"/>
                                </p:column>
                                <p:column headerText="Edit" style="width: 40px">
                                    <div align="center">
                                        <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-pencil" onclick="dlgEditGroup.show()" update=":formEditGroup" action="#{cOMMUNICATION_CHANNELController.updateEditGroup()}"/>
                                    </div>
                                </p:column>
                                <p:column headerText="Delete" style="width: 40px">
                                    <div align="center">
                                        <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-trash" onclick="dlgDelGroup.show()" update=":formDelGroup" action="#{cOMMUNICATION_CHANNELController.updateRemoveGroup()}"/>
                                    </div>
                                </p:column>
                            </p:dataTable>                            
                        </h:form>
                    </p:dialog>
                    <!--dialog Add Group-->
                    <p:dialog widgetVar="dlgAddGroup" resizable="false" header="Thêm nhóm" modal="true">
                        <h:form id="formAddGroup">
                            <h:panelGrid columns="2">
                                <h:outputText value="Soure number: "/><h:outputText value="#{cOMMUNICATION_CHANNELController.current.source_number}"/>                                
                                <h:outputText value="Group: "/>
                                <p:selectOneMenu value="#{cOMMUNICATION_CHANNELController.group_id}">
                                    <f:selectItems value="#{cOMMUNICATION_CHANNELController.listGroup}" var="g" itemValue="#{g.group}" itemLabel="#{g.group_name}"/>                                
                                </p:selectOneMenu>
                                <h:outputText value="From date: "/>
                                <p:calendar value="#{cOMMUNICATION_CHANNELController.from_date}" showOn="button" pattern="dd-MM-yyyy"/>
                                <h:outputText value="To date: "/>
                                <p:calendar value="#{cOMMUNICATION_CHANNELController.to_date}" showOn="button" pattern="dd-MM-yyyy"/>
                            </h:panelGrid>
                            <p:commandButton value="Xác nhận" action="#{cOMMUNICATION_CHANNELController.insertGroup()}" update=":formSetGroup" oncomplete="dlgAddGroup.hide()"/>
                        </h:form>
                    </p:dialog>
                    <!--dialog Edit Group-->
                    <p:dialog widgetVar="dlgEditGroup" resizable="false" header="Sửa nhóm" modal="true">
                        <h:form id="formEditGroup">
                            <h:panelGrid columns="2">
                                <h:outputText value="Soure number: "/><h:outputText value="#{cOMMUNICATION_CHANNELController.current.source_number}"/>                                
                                <h:outputText value="Group: "/>
                                <p:selectOneMenu value="#{cOMMUNICATION_CHANNELController.group_id}" >
                                    <f:selectItems value="#{cOMMUNICATION_CHANNELController.listGroup}" var="g" itemValue="#{g.group}" itemLabel="#{g.group_name}"/>                                
                                </p:selectOneMenu>
                                <h:outputText value="From date: "/>
                                <p:calendar value="#{cOMMUNICATION_CHANNELController.from_date}" showOn="button" pattern="dd-MM-yyyy"/>
                                <h:outputText value="To date: "/>
                                <p:calendar value="#{cOMMUNICATION_CHANNELController.to_date}" showOn="button" pattern="dd-MM-yyyy"/>
                            </h:panelGrid>
                            <p:commandButton value="Xác nhận" action="#{cOMMUNICATION_CHANNELController.updateGroup()}" update=":formSetGroup" oncomplete="dlgEditGroup.hide()"/>
                        </h:form>
                    </p:dialog>
                    <!--dialog Del Group-->
                    <p:dialog widgetVar="dlgDelGroup" resizable="false" header="Xóa nhóm" modal="true">
                        <h:form id="formDelGroup">
                            <h:outputText value="Bạn chắc chắn muốn xóa bản ghì này?"/>
                            <p:commandButton value="Xác nhận" action="#{cOMMUNICATION_CHANNELController.removeGroup()}" update=":formSetGroup" oncomplete="dlgDelGroup.hide()"/>
                        </h:form>
                    </p:dialog>
                </p:layoutUnit>
                <p:layoutUnit id="bottom" position="bottom" size="60">
                    <ui:insert name="footer">
                        <ui:include src="../../templates/footer.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>
            </div>
        </div>
    </h:body>
</html>

